<?php
namespace app\admin\middleware;
use app\common\Apiv;
use think\Facade\Db;
/**
 * @author KEL
 * @登录验证 
 * @Date   2020-07-09 17:34:42
 * @Author  <1067547248@qq.com>
 */
class LoginCheck{
	public function handle($request, \Closure $next){
		$token = input('token');
		if(!$token){
			return Apiv::result(0,1200);
		}
		$info = Db::name('sys_user')->field('id,role_ids,is_admin,status')->where('token', $token)->find();
		if(!$info){
			return Apiv::result(0,1201);
		}
		if($info['status']!=1){
			return Apiv::result(0,1202);
		}
		$request->role_ids = $info['role_ids']; //用户角色
		$request->is_admin = $info['is_admin']; //是否超级管理员
		return $next($request);
    }

    public function end(\think\Response $response){
        // 回调行为
        // return $response;
    }
}